|
|
|
|
|
|
|
txtState.Width = .ScaleWidth / 2 - 500
'Move the Zipcode text box
txtZip.Left = .ScaleWidth / 2 + 160
lblZip.Left = .ScaleWidth / 2 + 160
End With
End Sub |
|
|
|
|
|
|
|
|
4. Save the changes to your project. |
|
|
|
|
|
|
|
|
|
The size numbers in the sample Resize event code are arbitrary. Their purpose is to keep the control's interface looking okay when the developer sizes it.  |
|
|
|
|
|
|
|
|
|
|
As the user changes the dimensions of the Address control, the Resize event procedure is executed. The first two lines in the preceding code sample prevent the user from making the control instance too small. The remaining lines resize all the constituent controls based on the size of the UserControl object. |
|
|
|
|
|
|
|
|
Adding a New Property to Your Control |
|
|
|
|
|
|
|
|
Including multiple text boxes within a single ActiveX control groups them visually and allows you to draw all the text boxes on the form at once. However, for an ActiveX control to be useful, you also need to be able to access its properties, methods, and events as a single control. In other words, if you intend to treat all the constituent controls separately from code, you really have not gained anything by combining them into one control. In the case of the Address control, the purpose of the control is to provide a way to enter address information. For this reason, you will create an AddressText property on the Address control that is much like the Text property of a text box. The difference here is that the AddressText property returns text from all the text boxes on the form in a single string. |
|
|
|
|
|
|
|
|
For simplicity's sake, the property will be read-only, using the Get property procedure. (Property procedures are discussed in Chapter 16, "Classes: Reusable Components.") |
|
|
|
|
|
|
|
|
See "Property Procedures," p. 363 |
|
|
|
|
|
|
|
|
To set up this property, open the Code window for the UserControl, and add the following procedure code: |
|
|
|
|
|
|
|
|
Public Property Get AddressText() As String
Dim s As String
s = txtName & vbCrLf
s = s & txtStreet & vbCrLf
s = s & txtCity & vbCrLf
s = s & txtState & vbCrLf
s = s & txtZip
AddressText = s
End Property |
|
|
|
|
|
|
|
|
The Property Get procedure code is not complex; it just combines the contents of the constituent controls and returns a single string to the calling application. However, the creation of this |
|
|
|
|
|